package com.hfut.wxy.entity.mysql;

import com.hfut.wxy.common.parent.WxyBase;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.Date;

@Getter
@Setter
@Entity
@Table(name = "wxyorder")
@DynamicInsert
@DynamicUpdate
public class WxyOrder extends WxyBase {

    @Column(columnDefinition = "Integer(1) default 0 comment '订单类型(保留字段)'")
    private Integer type;

    @Column(columnDefinition = "Integer(1) default 0  comment '订单状态(0等待接单 1正在派单 2订单锁定中)'")
    @ApiModelProperty(notes = "0等待接单 1正在派单 2已完成等待收货 3订单已完成 4订单锁定中 5仲裁中 6协商已处理 7仲裁已处理")
    private Integer state;

    @Column(columnDefinition = "Integer(1) comment '支付类型'")
    private Integer payType;

    @Column(columnDefinition = "datetime comment '完成时间'")
    @ApiModelProperty(hidden = true)
    private Date finishTime;

    @Column(columnDefinition = "varchar(8) comment '取件码'")
    private String code;

    @Column(columnDefinition = "varchar(6) comment '取件人姓名'")
    private String name;

    @Column(columnDefinition = "varchar(13) comment '取件号码'")
    private String pickUpPhone;

    @Column(columnDefinition = "datetime comment '预约送达时间'")
    @ApiModelProperty(example = "2020-01-01 00:00:00")
    private Date deliveryTime;

    @Column(columnDefinition = "varchar(255) comment '备注'")
    private String comment;

    @Column(columnDefinition = "float(5,2) comment '佣金'")
    private Float commission;

    @Column(columnDefinition = "int(1) default '1' comment '版本号(实现乐观锁)'")
    private Integer version;

    @Column(columnDefinition = "int(2) comment'快递公司'")
    private Integer expressCompany;

    @Column(columnDefinition = "int(1) comment'包裹大小'")
    //0 1 2 3
    private Integer volume;

    @ManyToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "pickUpAddressId")
    private WxyPickUpAddress pickUpAddress;

    @ManyToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "creatorId")
    private WxyUserInfo creator;

    @ManyToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "executorId")
    private WxyUserInfo executor;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "addressId",foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private WxyAddress wxyAddress;


    public enum ExpressCompany{
        YUNDA("韵达"),
        ZHONGTONG("中通"),
        SHUNFENG("顺风");
        private final String name;

        ExpressCompany(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }


}
